#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <QString>
#include <QJsonObject>
#include <QJsonDocument>

// 消息类型定义
enum MessageType {
    // 认证相关
    MSG_LOGIN = 1000,
    MSG_LOGIN_RESPONSE,
    MSG_REGISTER,
    MSG_REGISTER_RESPONSE,
    MSG_LOGOUT,
    
    // 患者相关
    MSG_GET_PATIENT_INFO = 2000,
    MSG_GET_PATIENT_INFO_RESPONSE,
    MSG_UPDATE_PATIENT_INFO,
    MSG_UPDATE_PATIENT_INFO_RESPONSE,
    MSG_MAKE_APPOINTMENT,
    MSG_MAKE_APPOINTMENT_RESPONSE,
    MSG_CANCEL_APPOINTMENT,
    MSG_CANCEL_APPOINTMENT_RESPONSE,
    MSG_GET_APPOINTMENTS,
    MSG_GET_APPOINTMENTS_RESPONSE,
    MSG_GET_APPOINTMENT_DETAIL,
    MSG_GET_APPOINTMENT_DETAIL_RESPONSE,
    MSG_GET_MEDICAL_RECORDS,
    MSG_GET_MEDICAL_RECORDS_RESPONSE,
    MSG_GET_PRESCRIPTIONS,
    MSG_GET_PRESCRIPTIONS_RESPONSE,
    
    // 医生相关
    MSG_GET_DOCTOR_INFO = 3000,
    MSG_GET_DOCTOR_INFO_RESPONSE,
    MSG_UPDATE_DOCTOR_INFO,
    MSG_UPDATE_DOCTOR_INFO_RESPONSE,
    MSG_GET_DOCTOR_SCHEDULE,
    MSG_GET_DOCTOR_SCHEDULE_RESPONSE,
    MSG_SET_DOCTOR_SCHEDULE,
    MSG_GET_PATIENT_LIST,
    MSG_GET_PATIENT_LIST_RESPONSE,
    MSG_CREATE_MEDICAL_RECORD,
    MSG_CREATE_MEDICAL_RECORD_RESPONSE,
    MSG_CREATE_PRESCRIPTION,
    MSG_CREATE_PRESCRIPTION_RESPONSE,
    MSG_CREATE_EXAM_REQUEST,
    MSG_CREATE_EXAM_REQUEST_RESPONSE,
    MSG_START_CONSULTATION,              // 开始接诊
    MSG_START_CONSULTATION_RESPONSE,
    MSG_FINISH_CONSULTATION,             // 完成就诊
    MSG_FINISH_CONSULTATION_RESPONSE,
    MSG_CHECK_APPOINTMENT_COMPLETION,    // 检查预约完成情况
    MSG_CHECK_APPOINTMENT_COMPLETION_RESPONSE,
    
    // 挂号缴费
    MSG_GET_DEPARTMENTS = 4000,
    MSG_GET_DEPARTMENTS_RESPONSE,
    MSG_GET_DOCTORS_BY_DEPT,
    MSG_GET_DOCTORS_BY_DEPT_RESPONSE,
    MSG_PAYMENT,
    MSG_PAYMENT_RESPONSE,
    MSG_GET_PAYMENT_HISTORY,
    MSG_GET_PAYMENT_HISTORY_RESPONSE,
    
    // 医患沟通
    MSG_GET_ALL_DOCTORS = 5000,               // 获取所有医生列表
    MSG_GET_ALL_DOCTORS_RESPONSE,
    MSG_GET_CHAT_PATIENTS,                    // 获取有沟通记录的患者列表
    MSG_GET_CHAT_PATIENTS_RESPONSE,
    MSG_SEND_MESSAGE,                         // 发送消息
    MSG_SEND_MESSAGE_RESPONSE,
    MSG_GET_CHAT_HISTORY,                     // 获取聊天历史
    MSG_GET_CHAT_HISTORY_RESPONSE,
    MSG_GET_UNREAD_COUNT,                     // 获取未读消息数
    MSG_GET_UNREAD_COUNT_RESPONSE,
    MSG_MARK_AS_READ,                         // 标记消息为已读
    MSG_MARK_AS_READ_RESPONSE,
    
    // 考勤管理
    MSG_ATTENDANCE_CHECKIN = 6000,            // 打卡
    MSG_ATTENDANCE_CHECKIN_RESPONSE,
    MSG_ATTENDANCE_CANCEL,                    // 取消打卡
    MSG_ATTENDANCE_CANCEL_RESPONSE,
    MSG_GET_ATTENDANCE_RECORDS,               // 获取打卡记录
    MSG_GET_ATTENDANCE_RECORDS_RESPONSE,
    MSG_GET_TODAY_ATTENDANCE,                 // 获取今日打卡状态
    MSG_GET_TODAY_ATTENDANCE_RESPONSE,
    MSG_CREATE_LEAVE_REQUEST,                 // 提交请假申请
    MSG_CREATE_LEAVE_REQUEST_RESPONSE,
    MSG_CANCEL_LEAVE_REQUEST,                 // 取消请假申请
    MSG_CANCEL_LEAVE_REQUEST_RESPONSE,
    MSG_GET_LEAVE_REQUESTS,                   // 获取请假记录
    MSG_GET_LEAVE_REQUESTS_RESPONSE,
    MSG_CANCEL_LEAVE,                         // 销假
    MSG_CANCEL_LEAVE_RESPONSE,
    
    // 药物查询
    MSG_GET_POPULAR_MEDICINES,
    MSG_GET_POPULAR_MEDICINES_RESPONSE,
    MSG_SEARCH_MEDICINES,
    MSG_SEARCH_MEDICINES_RESPONSE,
    
    // 通知相关
    MSG_GET_NOTIFICATIONS = 7000,           // 获取通知列表
    MSG_GET_NOTIFICATIONS_RESPONSE,
    MSG_PUSH_NOTIFICATION,                  // 服务端主动推送通知
    MSG_MARK_NOTIFICATION_READ,             // 标记通知为已读
    MSG_MARK_NOTIFICATION_READ_RESPONSE,
    MSG_CLEAR_ALL_NOTIFICATIONS,            // 清空所有通知
    MSG_CLEAR_ALL_NOTIFICATIONS_RESPONSE,
    
    // 系统消息
    MSG_ERROR = 9000,
    MSG_SUCCESS = 9001
};

// 用户角色
enum UserRole {
    ROLE_PATIENT = 1,
    ROLE_DOCTOR = 2,
    ROLE_ADMIN = 3
};

// 协议类
class Protocol {
public:
    static QByteArray createMessage(MessageType type, const QJsonObject& data);
    static bool parseMessage(const QByteArray& data, MessageType& type, QJsonObject& jsonData);
    static QJsonObject createErrorResponse(const QString& error);
    static QJsonObject createSuccessResponse(const QString& message);
};

#endif // PROTOCOL_H

